package com.drinks.yiniang.io.api;

import android.support.annotation.NonNull;

import com.alibaba.fastjson.JSON;
import com.drinks.yiniang.common.help.PayManager;
import com.drinks.yiniang.entity.common.HotLineJson;
import com.drinks.yiniang.entity.common.StringJson;
import com.drinks.yiniang.entity.pay.AliPayJson;
import com.drinks.yiniang.entity.pay.WeiXinPayJson;
import com.drinks.yiniang.entity.user.DrawCashInfoJson;
import com.drinks.yiniang.entity.user.UserInfoJson;
import com.drinks.yiniang.entity.user.UserSetJson;
import com.drinks.yiniang.entity.user.achievement.AchievementJson;
import com.drinks.yiniang.entity.user.address.AddressInfoJson;
import com.drinks.yiniang.entity.user.address.DeliverAddressJson;
import com.drinks.yiniang.entity.user.friends.FriendsJson;
import com.drinks.yiniang.entity.user.wallet.RechargePackageJson;
import com.drinks.yiniang.entity.user.wallet.WalletInfoJson;
import com.drinks.yiniang.io.http.HttpUrls;
import com.hansen.library.Constants;
import com.hansen.library.entity.BaseJson;
import com.hansen.library.io.tuple.Tuple2;
import com.hansen.library.listener.APIRequestCallback;
import com.hansen.library.utils.LogUtils;
import com.hansen.library.utils.MD5Util;

/**
 * 用户api
 * Created by han on 2019/3/6 0006.
 */

public class UserApiIO extends BaseApiIO {
    volatile static UserApiIO instance;

    static public UserApiIO getInstance() {
        if (instance == null) {
            synchronized (UserApiIO.class) {
                if (instance == null) {
                    instance = new UserApiIO();
                }
            }
        }
        return instance;
    }

    /**
     * 用户信息
     *
     * @param callback
     */
    public void getUserInfo(final APIRequestCallback<UserInfoJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();

        MainApiIO.getInstance().postRequest(HttpUrls.API_USER_INFO, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("用户信息===onSuccess");

                UserInfoJson mDataJson = JSON.parseObject(res, UserInfoJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 修改个人信息
     *
     * @param key      参数键
     * @param value    参数值
     * @param callback
     */
    public void modifyUserInfo(@NonNull String key, String value, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();

        paramsMap.put(key, value);

        MainApiIO.getInstance().postRequest(HttpUrls.API_MODIFY_USER_INFO, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("修改个人信息===onSuccess");

                BaseJson mDataJson = JSON.parseObject(res, BaseJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 修改个人信息
     *
     * @param avatar
     * @param nickName
     * @param sex
     * @param signature
     * @param cover
     * @param callback
     */
    public void modifyUserInfo(String avatar, String nickName, String sex, String signature, String cover, final APIRequestCallback<UserInfoJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();

        paramsMap.put("avatar", avatar);
        paramsMap.put("username", nickName);
        paramsMap.put("sex", sex);
        paramsMap.put("signature", signature);
        paramsMap.put("cover_url", cover);

        MainApiIO.getInstance().postRequest(HttpUrls.API_MODIFY_USER_INFO, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("修改个人信息===onSuccess");

                UserInfoJson mDataJson = JSON.parseObject(res, UserInfoJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 钱包信息
     *
     * @param callback
     */
    public void getWalletInfo(final APIRequestCallback<WalletInfoJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();

        MainApiIO.getInstance().postRequest(HttpUrls.API_WALLET_INFO, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("钱包信息===onSuccess");

                WalletInfoJson mDataJson = JSON.parseObject(res, WalletInfoJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 我的成就
     *
     * @param callback
     */
    public void getMyArchievement(final APIRequestCallback<AchievementJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();

        MainApiIO.getInstance().postRequest(HttpUrls.API_MY_ACHIEVEMENT, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("我的成就===onSuccess");

                AchievementJson mDataJson = JSON.parseObject(res, AchievementJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getList() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 充值套餐列表
     *
     * @param callback
     */
    public void getRechargePackageList(final APIRequestCallback<RechargePackageJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();

        MainApiIO.getInstance().postRequest(HttpUrls.API_RECHARGE_PACKAGE_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("充值套餐列表===onSuccess");

                RechargePackageJson mDataJson = JSON.parseObject(res, RechargePackageJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 充值套餐购买
     *
     * @param id       套餐id
     * @param callback
     */
    public void doRechargeByAlipay(String id, final APIRequestCallback<AliPayJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("recharge_packages_id", id);
        paramsMap.put("pay_type", String.valueOf(PayManager.PAY_CHANNEL_ALIPAY));

        MainApiIO.getInstance().postRequest(HttpUrls.API_RECHARGE_PACKAGE_BUY, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("充值套餐购买===onSuccess");

                AliPayJson mDataJson = JSON.parseObject(res, AliPayJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 充值套餐购买
     *
     * @param id       套餐id
     * @param callback
     */
    public void doRechargeByWeiXinPay(String id, final APIRequestCallback<WeiXinPayJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("recharge_packages_id", id);
        paramsMap.put("pay_type", String.valueOf(PayManager.PAY_CHANNEL_WX));

        MainApiIO.getInstance().postRequest(HttpUrls.API_RECHARGE_PACKAGE_BUY, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("充值套餐购买===onSuccess");

                WeiXinPayJson mDataJson = JSON.parseObject(res, WeiXinPayJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 好友列表
     *
     * @param type     类型 1 我的关注 2我的粉丝
     * @param page     页码
     * @param callback
     */
    public void getFriendsList(String type, int page, final APIRequestCallback<FriendsJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("type", type);
        paramsMap.put("page", String.valueOf(page));
        paramsMap.put("per_page", Constants.PAGE_SIZE);

        MainApiIO.getInstance().postRequest(HttpUrls.API_MY_FRIENDS_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("好友列表===onSuccess");

                FriendsJson mDataJson = JSON.parseObject(res, FriendsJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    //*********************************************收货地址*****************************************

    /**
     * 收货地址列表
     *
     * @param callback
     */
    public void getDeliverAddressList(final APIRequestCallback<DeliverAddressJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();

        MainApiIO.getInstance().postRequest(HttpUrls.API_DELIVER_ADDRESS_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("收货地址列表===onSuccess");

                DeliverAddressJson mDataJson = JSON.parseObject(res, DeliverAddressJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 收货地址详情
     *
     * @param addressId 收货地址id
     * @param callback
     */
    public void getDeliverAddressInfo(String addressId, final APIRequestCallback<AddressInfoJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("address_id", addressId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_ADDRESS_DETAIL, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("收货地址详情===onSuccess");

                AddressInfoJson mDataJson = JSON.parseObject(res, AddressInfoJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 删除收货地址
     *
     * @param addressId 收货地址id
     * @param callback
     */
    public void deleteDeliverAddress(String addressId, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("id", addressId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_DELETE_ADDRESS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("删除收货地址===onSuccess");

                BaseJson mDataJson = JSON.parseObject(res, BaseJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 添加收货地址
     *
     * @param name       收货人姓名
     * @param mobile     手机号
     * @param provinceId 省份id
     * @param cityId     城市id
     * @param districtId 区id
     * @param address    详细地址
     * @param isDefault  是否默认 1-默认， 0-不是默认
     * @param callback
     */
    public void addDeliverAddress(String name, String mobile, String provinceId, String cityId, String districtId, String address,
                                  String isDefault, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("real_name", name);
        paramsMap.put("mobile", mobile);
        paramsMap.put("province_id", provinceId);
        paramsMap.put("city_id", cityId);
        paramsMap.put("district_id", districtId);
        paramsMap.put("address", address);
        paramsMap.put("is_default", isDefault);

        MainApiIO.getInstance().postRequest(HttpUrls.API_ADD_ADDRESS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("添加收货地址===onSuccess");

                BaseJson mDataJson = JSON.parseObject(res, BaseJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 修改收货地址
     *
     * @param addressId  地址id
     * @param name       收货人姓名
     * @param mobile     手机号
     * @param provinceId 省份id
     * @param cityId     城市id
     * @param districtId 区id
     * @param address    详细地址
     * @param isDefault  是否默认 1-默认， 0-不是默认
     * @param callback
     */
    public void modifyDeliverAddress(String addressId, String name, String mobile, String provinceId, String cityId, String districtId, String address,
                                     String isDefault, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("id", addressId);
        paramsMap.put("real_name", name);
        paramsMap.put("mobile", mobile);
        paramsMap.put("province_id", provinceId);
        paramsMap.put("city_id", cityId);
        paramsMap.put("district_id", districtId);
        paramsMap.put("address", address);
        paramsMap.put("is_default", isDefault);

        MainApiIO.getInstance().postRequest(HttpUrls.API_MODIFY_ADDRESS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("修改收货地址===onSuccess");

                BaseJson mDataJson = JSON.parseObject(res, BaseJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 设置页面富文本
     *
     * @param type     0 开设厂区 1大宗采购 2关于我们
     * @param callback
     */
    public void getHtmlFromSettingPage(String type, final APIRequestCallback<StringJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("type", type);

        MainApiIO.getInstance().postRequest(HttpUrls.API_HTML_SET_PAGE, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("设置页面富文本===onSuccess");

                StringJson mDataJson = JSON.parseObject(res, StringJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 获取电话客服热线时间
     *
     * @param callback
     */
    public void getTelephoneHotLineTime(final APIRequestCallback<HotLineJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();

        MainApiIO.getInstance().postRequest(HttpUrls.API_TELPHONE_HOT_LINE_TIME, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("获取电话客服热线时间===onSuccess");

                HotLineJson mDataJson = JSON.parseObject(res, HotLineJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    //-----------------------------------------提现相关信息------------------------------------------

    /**
     * 获取提现信息
     *
     * @param callback
     */
    public void getDrawCashInfo(final APIRequestCallback<DrawCashInfoJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();

        MainApiIO.getInstance().postRequest(HttpUrls.API_DRAWCASH_INFO, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("获取提现信息===onSuccess");

                DrawCashInfoJson mDataJson = JSON.parseObject(res, DrawCashInfoJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 设置支付宝账号
     *
     * @param name     支付宝姓名
     * @param account  支付宝账号
     * @param callback
     */
    public void setAlipayAccount(String name, String account, final APIRequestCallback<StringJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("alipay_name", name);
        paramsMap.put("alipay_account", account);

        MainApiIO.getInstance().postRequest(HttpUrls.API_SET_ALIPAY_ACCOUNT, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("设置支付宝账号===onSuccess");

                StringJson mDataJson = JSON.parseObject(res, StringJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 申请提现
     *
     * @param amount   提现金额
     * @param callback
     */
    public void doApplyDrawCash(String amount, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("amount", amount);

        MainApiIO.getInstance().postRequest(HttpUrls.API_APPLY_DRAWCASH, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("申请提现===onSuccess");

                BaseJson mDataJson = JSON.parseObject(res, BaseJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 设置支付密码
     *
     * @param isOpenPassword  是否开启支付 1开启 0否
     * @param password 密码（不为空时，修改密码, 密码统一md5加密）
     * @param callback
     */
    public void setPayPassword(String isOpenPassword, String password, final APIRequestCallback<StringJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("open_pay", isOpenPassword);
        paramsMap.put("pay_password", MD5Util.md5(password));

        MainApiIO.getInstance().postRequest(HttpUrls.API_SET_PAY_PASSWORD, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("设置支付密码===onSuccess");

                StringJson mDataJson = JSON.parseObject(res, StringJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 验证支付密码
     *
     * @param password 密码（不为空时，修改密码, 密码统一md5加密）
     * @param callback
     */
    public void doPayPasswordVerify(String password, final APIRequestCallback<StringJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("pay_password", MD5Util.md5(password));

        MainApiIO.getInstance().postRequest(HttpUrls.API_VERIFY_PAY_PASSWORD, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("验证支付密码===onSuccess");

                StringJson mDataJson = JSON.parseObject(res, StringJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 获取用户是否设置过密码，是否开启密码支付，是否专家
     *
     * @param callback
     */
    public void getUserSetData(final APIRequestCallback<UserSetJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();

        MainApiIO.getInstance().postRequest(HttpUrls.API_GET_USER_SET_DATA_INFO, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("获取用户是否设置过密码，是否开启密码支付，是否专家===onSuccess");

                UserSetJson mDataJson = JSON.parseObject(res, UserSetJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }
}
